var WxParse = require("../../wxParse/wxParse.js");

Page({
    data: {
        version: getApp()._version,
        article: []
    },
    onLoad: function(e) {
        getApp().page.onLoad(this, e);
        var t = this;
        getApp().request({
            url: getApp().api.default.article_detail,
            data: {
                id: e.id
            },
            success: function(e) {
                if(0 == e.code) {
                    getApp().core.setNavigationBarTitle({
                        title: e.data.title
                    }), e.data.img = e.data.img.split(","), e.data.copyuser_tel = e.data.tel.substr(0,3) + "****" + e.data.tel.substr(7);
                    t.setData({
                        article: e.data
                    });
                    var c = e.data.content ? e.data.content : "<span>暂无信息</span>";
                    WxParse.wxParse("detail", "html", c, t);

                } else {
                    getApp().core.showModal({
                        title: "提示",
                        content: e.msg,
                        showCancel: !1,
                        confirm: function(e) {
                            e.confirm && getApp().core.navigateBack();
                        }
                    });
                }
                
                /* 0 == e.code && (getApp().core.setNavigationBarTitle({
                    title: e.data.title
                }), WxParse.wxParse("content", "html", e.data.content, t)), 1 == e.code && getApp().core.showModal({
                    title: "提示",
                    content: e.msg,
                    showCancel: !1,
                    confirm: function(e) {
                        e.confirm && getApp().core.navigateBack();
                    }
                }); */
            }
        });
    },

    phone: function(e) {
        var a = this, o = a.data.article;
        wx.makePhoneCall({
          phoneNumber: o.tel,
        })
    },

    gomch: function(t) {
        var a = this, o = t.currentTarget.dataset.mch_id;
        getApp().core.navigateTo({
            url: '/mch/shop/shop?mch_id=' + o
        })
    },

    thumbs_up: function(t) {
        var a = this, n = a.data.article;
        getApp().request({
            url: getApp().api.default.article_like,
            cachetime: "0",
            data: {
                id: n.id
            },
            success: function(t) {
               1 == t.code ? getApp().core.showModal({
                   title: '提示',
                   content: t.msg,
                   showCancel: !1
               }) : (n.givelike = Number(n.givelike) + 1, a.setData({
                   article: n
               }));
            }
        })
    },

    onShareAppMessage: function(t) {
        return getApp().page.onShareAppMessage(this), {
            path: "/pages/article-detail/article-detail?id="+this.data.article.id+"&user_id=" + getApp().core.getStorageSync(getApp().const.USER_INFO).id
        };
    }
});